<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
	<h:head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<link rel="stylesheet"
			href="${request.contextPath}/resources/css/style.css" type="text/css"
			media="screen" />
		<link rel="stylesheet"
			href="${request.contextPath}/resources/css/styleButton.css"
			type="text/css" media="screen" />
		<link rel="shortcut icon"
			href="${request.contextPath}/resources/img/favicon.ico" />
		<title><ui:insert name="title"></ui:insert></title>
	</h:head>
	<h:body>
		<div id="page">
			<div id="menu">
				<ui:insert name="header">
					<center>
						<ui:include src="/template/commonHeader.xhtml" />
					</center>
				</ui:insert>
			</div>
			<div id="line" />
			<div id="content">
				<br />
				<h:form id="formIndexStudent">
					<p:commandButton value="&nbsp;#{Button.add_new_student}"
						styleClass="addButton"
						action="#{studentController.preparedAdding()}"
						oncomplete="handleStudentAddRequest(xhr, status, args)" />
				</h:form>
				<br />
				<!-- List Student -->
				<h:form id="formListStudent">
					<p:dataTable id="listDatatable" var="studentList"
						value="#{studentController.studentList}"
						style="width:90%; padding-top: 3px; padding-bottom: 10px; padding-left: 5%;  vertical-align: top;"
						paginator="true" rows="24"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						paginatorPosition="bottom" rowsPerPageTemplate="12,24,36"
						selection="#{studentController.student}"
						rowKey="#{studentList.userStudent.user_number}"
						selectionMode="single" widgetVar="studentTable"
						emptyMessage="No student found with given criteria"
						filteredValue="#{studentController.filterStudents}"
						draggableColumns="false" resizableColumns="true">
						<p:ajax event="rowSelect"
							listener="#{studentController.onRowSelect}"
							update=":formListStudent:panelGrid"
							oncomplete="studentDialog.show()" />

						<p:column sortBy="#{studentList.name}"
							filterBy="#{studentList.name}" headerText="NAME">
							<h:outputText value="#{studentList.name}" />
						</p:column>

						<p:column headerText="SURNAME">
							<h:outputText value="#{studentList.surname}" />
						</p:column>


						<p:column headerText="STUDENT NUMBER"
							sortBy="#{studentList.userStudent.user_number}"
							filterBy="#{studentList.userStudent.user_number}">
							<h:outputText value="#{studentList.userStudent.user_number}" />
						</p:column>

						<p:column headerText="T.C NUMBER">
							<h:outputText value="#{studentList.tc_number}" />
						</p:column>

						<p:column headerText="GENDER">
							<h:outputText value="#{studentList.userStudent.sex}" />
						</p:column>

						<p:column style="width:8%">
							<p:commandButton update=":formEditStudent:panelEditGrid"
								oncomplete="studentEditDialog.show()" icon="ui-icon-wrench"
								title="Edit" />&nbsp;&nbsp;
		                    <p:commandButton
								update=":formDeleteStudent:panelDeleteGrid"
								oncomplete="studentDeleteDialog.show()" icon="ui-icon-trash"
								title="Delete" />
						</p:column>

					</p:dataTable>

					<p:dialog header="Student Detail" widgetVar="studentDialog"
						resizable="false" showEffect="explode" hideEffect="explode"
						styleClass="dialogback">
						<h:panelGrid id="panelGrid" columns="2" cellpadding="4">

							<f:facet name="header">
								<h:outputText
									value="#{studentController.student.name}  #{studentController.student.surname}"
									style="font-weight:bold" />
							</f:facet>

							<h:panelGroup>
								<h:outputText value="Student Number  " />
								<h:outputText style="color:red; float: right" value=" : " />
							</h:panelGroup>
							<h:outputText
								value="#{studentController.student.userStudent.user_number}"
								style="font-weight:bold" />

							<h:panelGroup>
								<h:outputText value="T.C Number " />
								<h:outputText style="color:red; float: right" value=" : " />
							</h:panelGroup>
							<h:outputText value="#{studentController.student.tc_number}"
								style="font-weight:bold" />

							<h:panelGroup>
								<h:outputText value="Gender " />
								<h:outputText style="color:red; float: right" value=" : " />
							</h:panelGroup>
							<h:outputText
								value="#{studentController.student.userStudent.sex}"
								style="font-weight:bold" />

							<h:panelGroup>
								<h:outputText value="Birth Date " />
								<h:outputText style="color:red; float: right" value=" : " />
							</h:panelGroup>
							<h:outputText value="#{studentController.student.birth_date}"
								style="font-weight:bold" />

							<h:panelGroup>
								<h:outputText value="Password " />
								<h:outputText style="color:red; float: right" value=" : " />
							</h:panelGroup>
							<h:outputText
								value="#{studentController.student.userStudent.password}"
								style="font-weight:bold" />


							<h:panelGroup>
								<h:outputText value="E-Mail " />
								<h:outputText style="color:red; float: right" value=" : " />
							</h:panelGroup>
							<h:outputText value="#{studentController.student.email}"
								style="font-weight:bold" />

							<h:panelGroup>
								<h:outputText value="Tel Number " />
								<h:outputText style="color:red; float: right" value=" : " />
							</h:panelGroup>
							<h:outputText value="#{studentController.student.tel_number}"
								style="font-weight:bold" />

							<h:panelGroup>
								<h:outputText value="City " />
								<h:outputText style="color:red; float: right" value=" : " />
							</h:panelGroup>
							<h:outputText
								value="#{studentController.student.userStudent.address.city}"
								style="font-weight:bold" />

							<h:panelGroup>
								<h:outputText value="Address Detail " />
								<h:outputText style="color:red; float: right" value=" : " />
							</h:panelGroup>
							<h:outputText
								value="#{studentController.student.userStudent.address.address_detail}"
								style="font-weight:bold" />

							<h:panelGroup>
								<h:outputText value="Record Date " />
								<h:outputText style="color:red; float: right" value=" : " />
							</h:panelGroup>
							<h:outputText
								value="#{studentController.student.userStudent.record_date}"
								style="font-weight:bold" />
						</h:panelGrid>
					</p:dialog>
				</h:form>

				<h:form id="formEditStudent">
					<p:dialog header="Edit Student Informatiom"
						widgetVar="studentEditDialog" resizable="false"
						showEffect="explode" hideEffect="explode">
						<h:panelGrid id="panelEditGrid" columns="2" cellpadding="4">

							<f:facet name="header">
								<h:outputText value="Under Construction !!!"
									style="font-weight:bold; color:red" />
							</f:facet>
						</h:panelGrid>
					</p:dialog>
				</h:form>

				<h:form id="formDeleteStudent">
					<p:growl id="growlDelete" sticky="true" />
					<p:confirmDialog id="studentDeleteDialog"
						message="Are you sure about deleting the field?"
						header="Initiating destroy process" severity="alert"
						widgetVar="studentDeleteDialog">

						<h:panelGrid id="panelDeleteGrid" columns="2" cellpadding="4">

							<f:facet name="header">
								<h:outputText value="Under Construction !!!"
									style="font-weight:bold; color:red" />
							</f:facet>
						</h:panelGrid>
					</p:confirmDialog>
				</h:form>
			</div>
			<div id="line" />
			<br />
			<div id="footer">
				<ui:insert name="footer">
					<ui:include src="/template/commonDock.xhtml" />
				</ui:insert>
			</div>
		</div>

		<script type="text/javascript">
			 	function handleStudentAddRequest(xhr, status, args) {
		        	window.location = "${request.contextPath}/flows/actions/newstudent.jsf?execution=n0s2";
			 	}
			 	</script>

	</h:body>
</f:view>
</html>
